package com.eryos.gwt.estate.client.view.impl;

import com.eryos.gwt.estate.client.place.HomePlace;
import com.eryos.gwt.estate.client.view.HomeView;
import com.eryos.gwt.estate.moduleA.client.place.ModuleAPlace;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class HomeViewImpl extends Composite implements HomeView {

    private static HomeViewImplUiBinder uiBinder = GWT.create(HomeViewImplUiBinder.class);

    /** Presenter associated to the current View */
    private HomeView.Presenter presenter;

    @UiTemplate("HomeView.ui.xml")
    interface HomeViewImplUiBinder extends UiBinder<Widget, HomeViewImpl> {
    }

    @UiField
    Label moduleALink;
    @UiField
    Label welcomeLink;

    /**
     * Default Constructor.
     */
    public HomeViewImpl() {
        initUI();
    }

    /**
     * Initialization of UI.
     */
    protected void initUI() {
        initWidget(uiBinder.createAndBindUi(this));
    }

    @Override
    public void setPresenter(final HomeView.Presenter presenter) {
        this.presenter = presenter;

        /************ Widget Presenter ************/
    }

    /**
     * 
     */
    @Override
    public void refreshView() {
        // TODO
    }

    @UiHandler("welcomeLink")
    void handleWelcomeClick(ClickEvent e) {
        presenter.goTo(new HomePlace("Home"));
    }

    @UiHandler("moduleALink")
    void handleModuleClick(ClickEvent e) {
        presenter.goTo(new ModuleAPlace("ModuleA"));
    }

}
